package model.houseproject_commity.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import model.houseproject_commity.entity.Commity;
import model.houseproject_commity.entity.Result;
import model.houseproject_commity.entity.StatusCode;
import model.houseproject_commity.service.CommityService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by ws on 2019/6/25.
 */

@RestController
public class commityController {
@Autowired
    private CommityService commityService;
   @CrossOrigin
    @GetMapping("/subway/{metro}")
    public Result find(@PathVariable("metro")String metro){
        List<Commity> ktypeList = commityService.findAll("metro");
        Result result=new Result(true,20000,"查询成功",ktypeList);
        return result;
    }
    @CrossOrigin
    @GetMapping("/page/{pageNow}")
    public Result page(@PathVariable("pageNow")String pageNow){
        Integer pages= Integer.valueOf(pageNow);
        PageHelper.startPage(pages,5);
        List<Commity> commityList = commityService.findAlls();

        PageInfo<Commity> pageInfo = new PageInfo<>(commityList);

        Result result = new Result(true, StatusCode.OK,"查询成功",pageInfo);
        return  result;
    }
    @GetMapping("/checkbox/{commityaddress},{type},{subway}")
    public Result checkbox(@PathVariable("commityaddress")String commityaddress,@PathVariable("type")String type,@PathVariable("subway")String subway){
        List<Commity> findlist=commityService.checkboxfind("address","type","subway");
        Result result=new Result(true,20000,"筛选成功",findlist);
        return result;
    }
}
